Creating a Polygon
This example demonstrates how to create a polygon using an array of vertices and set basic properties. This example uses the ILinearRing, IGeometry, ITerrainPolygon80, ICreator80 (CreatePolygon, GeometryCreator), IGeometryCreator (CreateLinearRingGeometry, CreatePolygonGeometry) INavigate80 (FlyTo), and IPosition80 (Copy, Pitch) properties and methods.
private void GeometryPolygon()
{
string tMsg = String.Empty;
double[] cVerticesArray = null;
ILinearRing cRing = null;
IGeometry cPolygonGeometry = null;
ITerrainPolygon80 cPolygon = null;
try
{
//
// A. Instantiate TerraExplorer Object
//
var SGWorld = new SGWorld80();
//
// B. Create linear ring
//
{
//B1. Create vertices double array, each point in format x,z,y
cVerticesArray = new double[] {
-122.415025, 37.76059, 10,
-122.415868, 37.760546, 11,
-122.415922, 37.761244, 12,
-122.415592, 37.761254, 13,
-122.415557, 37.760973, 14,
-122.415081, 37.76099, 15,
};
// B2. Create linear ring using vertices
{
cRing = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray);
}
}
//
// C. Create polygon geometry using linear ring
//
{
cPolygonGeometry = SGWorld.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null);
}
//
// D. Create polygon using polygon geometry
//
{
// D1. Set polygon input params
uint nLineColor = 0xFF00FF00; // Abgr value -> solid green
uint nFillColor = 0x7FFF0000; // Abgr value -> 50% transparent blue
AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
// D2. Create polygon
cPolygon = SGWorld.Creator.CreatePolygon(cPolygonGeometry, nLineColor, nFillColor, eAltitudeTypeCode, string.Empty, "Polygon");
}
//
// E. FlyTo polygon
//
{
var cFlyToPos = cPolygon.Position.Copy();
cFlyToPos.Pitch = -89.0; // Set camera to look downward on polygon
SGWorld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);
}
}
catch (Exception ex)
{
tMsg = String.Format("GeometryPolygon_Click Exception: {0}", ex.Message);
MessageBox.Show(tMsg);
}
}